package com.DateDemo;
import java.text.SimpleDateFormat;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class dateClass {
    public static void main(String[] args) throws DateTimeException {
        Date date = new Date();
//        System.out.println(date);
//        long longDate = 1000*60*60;
//        Date date1 = new Date(longDate);
//        System.out.println(date1);
//        常用方法
//        getTime 获取的是日期对象从1970年1月1日00:00:00到现在的毫秒值
//        System.out.println(date.getTime());
        long time = System.currentTimeMillis();
        date.setTime(time);
        System.out.println(date);
//        SimpleDateFormat类
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String s = sdf.format(date);
        System.out.println(s);
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        LocalDateTime localDateTime =  LocalDateTime.of(2021,7,13,20,44,12);
//        System.out.println(localDateTime);
//        System.out.println(localDateTime.getYear());
//        System.out.println(localDateTime.getMonthValue());
//        System.out.println(localDateTime.getDayOfMonth());
//        System.out.println(localDateTime.getDayOfYear());
//        System.out.println(localDateTime.getDayOfWeek());
//        System.out.println(localDateTime.getMinute());
//        System.out.println(localDateTime.getHour());
//        LocalDate表达的是日期  LocalTime表达的是时间
        LocalTime localTime = localDateTime.toLocalTime();
        LocalDate localDate = localDateTime.toLocalDate();
        System.out.println(localTime);
        System.out.println(localDate);

//        LocalDateTime格式化解析
        String string = "2020年11月12日 13:14:15";
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse(string,pattern);
        System.out.println(parse);
//        获取本地时间案例
//        Date date2 = new Date();
//        date2.setTime(System.currentTimeMillis());
//        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//        System.out.println(sdf1.format(date2));
        System.out.println(new Date(31L*24*3600*1000));
    }
}
